package hibernate.method;

import hibernate.method.interfaces.LocalMethodsInterface;
import hibernate.model.Local;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.SessionFactory;

public class LocalMethods implements LocalMethodsInterface{

	@Override
	public List<Local> listAllLocals(SessionFactory sessionFactory,
			Session session) {
		Criteria cr = session.createCriteria(Local.class);
		@SuppressWarnings("unchecked")
		List<Local> llist = cr.list();
		return llist;
	}

	@Override
	public void addLocal(SessionFactory sessionFactory, Session session,
			String street, String local_number, String city, String province, String country, String description) {
		Local local = new Local();
		local.setStreet(street);
		local.setLocal_number(local_number);
		local.setCity(city);
		local.setProvince(province);
		local.setCountry(country);
		local.setDescription(description);
		session.save(local);
		
	}

	@Override
	public Local findLocalById(SessionFactory sessionFactory, Session session,
			int local_id) {
		Local local = (Local) session.get(Local.class, new Integer(local_id));
		return local;
	}

}
